<?

class mail_send_task extends system_task
{
	public function execute(array $params = array())
	{
		gearman::worker()->addFunction(config::get('mail_queue'), 'mail_send_task::handler');

		while (1)
		{
			$ret = gearman::worker()->work();
			if ( gearman::worker()->returnCode() != GEARMAN_SUCCESS ) break;
		}
	}

	public static function handler( $job )
	{
		$data = unserialize($job->workload());
		mail($data['to'], $data['subject'], $data['message'], $data['headers']);
	}
}